<#include "../header.html">
<script type="text/javascript">
	(function(window){
		var ext = "jpg,png,jpeg,gif";
		var size = ${imgSize!};
		var upload={
			initUpload:function(){
				$("#imgFile").change(Upload.checkUpload);
			},
			checkUpload:function(){
				var imgFile = $("#imgFile").val();
				if(imgFile==null || JFT.isBlank(imgFile)){
					alert("请选择上传的文件");
					return;
				}
				if(!JFT.checkFile(imgFile, ext)){
					alert("上传文件格式必须是["+ext+"]");
					return;
				}
				var fileSize = JFT.getFileSize("imgFile");
				if(fileSize!=-1 && fileSize>size){
					alert("上传图片文件最大不能超过"+(size/1024)+"K");
					return;
				}
				$("#uploadBtn", parent.document).html("文件上传中");
				$("#uploadBtn", parent.document).attr("disabled",true);
				$("#uploadForm").submit();
			},
			handleUpload:function(code, imgId, imgSrc,fileUrl){
				$("#uploadBtn", parent.document).attr("disabled",false);
				$("#uploadBtn", parent.document).html("上传图片");
				if(code == 0) {
					window.parent.renderDetailImg(imgId, imgSrc, fileUrl);
					return;
				}else if(code == 1){
					alert("上传失败");
					return;
				}else if(code == 2){
					alert("超过上传大小限制");
					return;
				} else if(code == 3) {
					alert("不支持的扩展名");
					return;
				}

			}
		};
		window.Upload = upload;
	})(window);
	$(function(){
	<#if resultCode?string != "-1">
				Upload.handleUpload("${resultCode!}", "${imgId!}", "${imgSrc!}", "${fileUrl!}");
	</#if>
		Upload.initUpload();
	});
</script>
<form id="uploadForm" name="uploadForm" method="post" action="momentAction.do?method=upload" enctype="multipart/form-data">
	<input type="hidden" id="imgType" name="imgType" value="4"/>
	<input type="hidden" id="imgId" name="imgId" value="${imgId!}"/>
	<input type="hidden" id="imgSrc" name="imgSrc" value="${imgSrc!}"/>
	<input type="file" id="imgFile" name="imgFile" class="e_hide"/>
</form>
<#include "../footer.html">